# base/base_page.py
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time

class BasePage:
    """页面基类"""

    def __init__(self, driver):
        self.driver = driver
        self.wait = WebDriverWait(driver, 3)

    def wait_seconds(self, seconds=2):
        """等待指定秒数"""
        time.sleep(seconds)

    def find_element(self, locator):
        """查找元素"""
        return self.wait.until(EC.presence_of_element_located(locator))

    def wait_element_clickable(self, locator, timeout=2):
        """等待元素可点击 - 新增方法"""
        return WebDriverWait(self.driver, timeout).until(
            EC.element_to_be_clickable(locator)
        )

    def find_elements(self, locator):
        """查找多个元素"""
        return self.wait.until(EC.presence_of_all_elements_located(locator))

    def type_text(self, locator, text):
        """输入文本"""
        element = self.find_element(locator)
        element.clear()
        self.wait_seconds(2)
        element.send_keys(text)
        self.wait_seconds(2)

    def click(self, locator):
        """点击元素"""
        self.wait_seconds(2)
        self.find_element(locator).click()
        self.wait_seconds(2)

    def get_title(self):
        """获取页面标题"""
        return self.driver.title